﻿using HuiZe.education.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HuiZe.education.Resource.Controls
{
    /// <summary>
    /// VideoPlayer2.xaml 的交互逻辑
    /// </summary>
    public partial class VideoPlayer2 : UserControl
    {
        public VideoPlayer2()
        {
            InitializeComponent();
            
            Loaded += PageManager_Loaded;
        }

        public string PlayUrl { get; set; }
        private void PageManager_Loaded(object sender, RoutedEventArgs e)
        {
            //mediaElement = new MediaElement();
            //mediaElement.LoadedBehavior = MediaState.Manual; ;
            mediaElement.Source = new Uri("ms-appx:///" + PlayUrl, UriKind.RelativeOrAbsolute);

            //mediaElement.Source = new Uri(Directory.GetCurrentDirectory()+ "\\Controls\\VideoPlay\\44.mp4", UriKind.RelativeOrAbsolute);

            mediaElement.Volume = 1000;
         

            mediaElement.Play();
            //deleteButton.ImageSource = new BitmapImage(new Uri(IsSelectdImgUrl, UriKind.Absolute));
        }

        private void Image_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var f = mediaElement.HasAudio;
            mediaElement.Play();
            mediaElement.ToolTip = "开始播放";
        }

        private void Image_MouseUp_1(object sender, MouseButtonEventArgs e)
        {
            mediaElement.Pause();
            mediaElement.ToolTip = "停止播放";
        }

        private void Image_MouseUp_2(object sender, MouseButtonEventArgs e)
        {
            mediaElement.Position = mediaElement.Position - TimeSpan.FromSeconds(10);

        }

        private void Image_MouseUp_3(object sender, MouseButtonEventArgs e)
        {
            mediaElement.Position = mediaElement.Position + TimeSpan.FromSeconds(10);
        }

        public bool DownFile(string url, string savepath)
        {
            var res = WebApiHelper.Download(url, savepath);
            if (res)
            {
                return res;
            }
            else
            {
                return false;
            }


        }

    }
}
